package thread;

import java.lang.ref.WeakReference;
import java.util.List;


public class ThreadLocalTest2 {

	public static void main(String[] args) {
		ThreadLocal a = new ThreadLocal();
		a.set("1");
		a.set("2");
		System.out.println(a.get());
		System.gc();
		System.out.println(a.get());
		
		
		
//		WeakReference<String> sr = new WeakReference<String>(new String("hello"));
//		System.out.println(sr.get());
//		System.gc();                //手工模拟JVM的gc进行垃圾回收
//		System.out.println(sr.get());
		
		
	}// 输出结果是2。貌似“1”被覆盖了。
	
	public void test() {
		ThreadLocal<String> threadLocal = new ThreadLocal<>();
		threadLocal.set("hello");
		System.out.println(threadLocal.get());
		
		
		ThreadLocal<String> threadLocal2 = new ThreadLocal<>();
		threadLocal2.set("hello2");
		System.out.println(threadLocal2.get());
		
		System.gc(); 
		threadLocal.remove();
		System.out.println(threadLocal.get());
		System.out.println(threadLocal2.get());
		
		
	}
	
	

}
